/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Interfaz.java
 *
 * Created on 16-abr-2013, 22:15:15
 */
package proyecto1compi1;


import Compilador.ErrorSintactico;
import Compilador.NodoError;
import Compilador.lexicoColorear;
import Compilador.lexicoColores;
import Compilador.lexicoLienzos;
import Compilador.sintacticoColorear;
import Compilador.sintacticoColores;
import Compilador.sintacticoLienzos;
import EditorImagenes.Editor;
import EditorImagenes.Ventana;
import EditorImagenes.escogerLienzos;
import java.awt.Color;
import java.awt.Desktop;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import javax.swing.JTextArea;

import java.io.FileWriter;
import java.io.IOException;
import java.io.StringReader;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @authora Mydelin
 */
public class Interfaz extends javax.swing.JFrame {
                
   public static LinkedList<Escenario> listaEscenarios = new  LinkedList<Escenario>();
   public static LinkedList<Colores> listColor = new LinkedList<Colores>();
   public static LinkedList<Colores> listColorear = new LinkedList<Colores>();
   
   public static LinkedList<NodoError> ListaDeErroresLexicos = new LinkedList<NodoError>();
   LinkedList<String> ListaDeToken = new LinkedList<String>();
   public static LinkedList<ColoresEscenario> ListaDeColoresDelEscenario=new LinkedList<ColoresEscenario>();
   public static LinkedList<ErrorSintactico> ListaDeErroresSintacticos = new LinkedList<ErrorSintactico>();
   LinkedList<String> ListaTokenSintactico = new LinkedList<String>();
   
   public static LinkedList<variables> listaVariables = new LinkedList<variables>();
   public static LinkedList<pintarEscenario> listadoPintarEscenario = new LinkedList<pintarEscenario>();

   
    public int buscar(String id){
		variables temporal=null;
		for(variables extra:this.listaVariables){
			if(extra.id.equals(id)){
				temporal=extra;
			}
			
		}
		return temporal.getValor();
	}
    
    
    
    String nombre = "";
    String direccion_dearchivo = "";
    
      String nombre1 = "";
    String direccion_dearchivo1 = "";
    
      String nombre2 = "";
    String direccion_dearchivo2 = "";
    
      String nombre3 = "";
    String direccion_dearchivo3 = "";
    String Inicio="<html><head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <style> table{ background:#000;color:#F9C;border: #700 solid 1px;}thead{background:#F39;padding: 3px 5px;color:#fff;font-size:1.2em;font-weight: bold;} td, th{	border-bottom: #333 solid 1px; border-right:#333 solid 1px;}tr:nth-child(even){	background:#222;}td:last-child,th:last-child{border-right:none;}tr:last-child td{border-bottom:none;}td,th{ margin: 0; padding: 3px 10px; vertical-align:top}</style> </head><body bgcolor=\"#C0D9D9\" \" +link=\"#000000\" vlink=\"magenta\" alink=\"#000000\"\"text=\"#FFFFFF\" background=\"tabla.gif\">         <center><u><i><font size=20 color=\"blue\"> T</font><font color=\"#F9C\">a<font><font color=\"blue\">b</font> <font><font color=\"blue\">l</font>a<font><font color=\"blue\">   </font>de <font><font color=\"blue\">T</font>oken</font></i></u></center>           <marquee><font color=\"#F9C\">Reporte de Errores</font></marquee>          <table Caption=\"tokens validos\" border=\"18\"Bgcolor=\"black\" cellspadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"futbol_c\"><caption style=\"text-align: center; font-size: 18px;\"><strong></strong></caption><tbody><thead><tr><th scope=\"col\" class=\"columna a20px\">Contador</th><th scope=\"col\" class=\"columna a20px\">Token</th><th scope=\"col\" class=\"columna  a30px\">Lexema</th><th scope=\"col\" class=\"columna  a30px\">Tipo de Error</th><th scope=\"col\" class=\"columna a20px\">Fila</th><th scope=\"col\" class=\"columna a20px\">Columna</th></tr></thead><tr><tr><strong>";
    String fin="</tbody></table></center></body></html>";

    
    
    /** Creates new form Interfaz */
    public Interfaz() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane2 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jButton9 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTextArea4 = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        jButton4 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTextArea3 = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jButton13 = new javax.swing.JButton();
        jButton14 = new javax.swing.JButton();
        jButton15 = new javax.swing.JButton();
        jButton16 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem9 = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/abrir.JPG"))); // NOI18N
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        jButton10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/guardar.gif"))); // NOI18N
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });

        jButton11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/nuevo.gif"))); // NOI18N
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });

        jButton12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/play.GIF"))); // NOI18N
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });

        jTextArea4.setColumns(20);
        jTextArea4.setRows(5);
        jScrollPane5.setViewportView(jTextArea4);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton10, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton12)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton10, 0, 0, Short.MAX_VALUE)
                    .addComponent(jButton9))
                .addGap(11, 11, 11)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane2.addTab("Lienzo", jPanel2);

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/guardar.gif"))); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/abrir.JPG"))); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/nuevo.gif"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/play.GIF"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTextArea3.setColumns(20);
        jTextArea3.setRows(5);
        jScrollPane4.setViewportView(jTextArea3);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 490, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)))
                .addContainerGap(21, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton4, 0, 0, Short.MAX_VALUE)
                    .addComponent(jButton3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane2.addTab("Colores", jPanel1);

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        jButton13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/abrir.JPG"))); // NOI18N
        jButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton13ActionPerformed(evt);
            }
        });

        jButton14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/guardar.gif"))); // NOI18N
        jButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton14ActionPerformed(evt);
            }
        });

        jButton15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/nuevo.gif"))); // NOI18N
        jButton15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton15ActionPerformed(evt);
            }
        });

        jButton16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/play.GIF"))); // NOI18N
        jButton16.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton16ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jButton13, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton15, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton16)
                        .addGap(29, 29, 29))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton16, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton15, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton14, 0, 0, Short.MAX_VALUE)
                    .addComponent(jButton13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane2.addTab("Colorear", jPanel3);

        jButton5.setText("Clear");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jMenuBar1.setBorder(new javax.swing.border.MatteBorder(null));

        jMenu1.setText("File");
        jMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu1ActionPerformed(evt);
            }
        });

        jMenuItem5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/cerrar.gif"))); // NOI18N
        jMenuItem5.setText("Cerrar");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem5);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Eventos");
        jMenu2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu2ActionPerformed(evt);
            }
        });

        jMenuItem9.setText("Mostrar Errores");
        jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem9ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem9);

        jMenuItem1.setText("Escoger Lienzo");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem1);

        jMenuItem2.setText("Acerca de");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem2);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jTabbedPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 526, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton5)
                        .addGap(89, 89, 89))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jTabbedPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 396, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

     public void limpiar(){
    listaEscenarios.clear();
            listColor.clear();
            listColorear.clear();
                    ListaDeErroresLexicos.clear();
                    ListaDeColoresDelEscenario.clear();
                            ListaDeErroresSintacticos.clear();
                            ListaTokenSintactico.clear();
                                    listaVariables.clear();
                                    listadoPintarEscenario .clear();
                                            } 
    void AbrirLienzos() {
        char letra;
        String Text = "";
        try {
            JFileChooser fc9 = new JFileChooser(System.getProperty("user.dir"));
            fc9.setMultiSelectionEnabled(false);
            fc9.setFileFilter(new FiltroLienzos (true));
            fc9.showOpenDialog(this);
            File Abrir = fc9.getSelectedFile();//Devuelve el File que vamos a leerName
            fc9.setFileSelectionMode(fc9.FILES_ONLY);
            if (Abrir != null) {
                nombre1 = fc9.getSelectedFile().getName();
            }
            if (Abrir != null) {
                jTextArea4.setText("");
                FileReader Fichero = new FileReader(Abrir);
                BufferedReader leer = new BufferedReader(Fichero);
                while ((Text = leer.readLine()) != null) {
                  jTextArea4.append(Text + "\n"); //append Concatena la linea leida
                }

                direccion_dearchivo1 = Abrir.getAbsolutePath();
                leer.close();

            }

        } catch (IOException ioe) {
            System.out.println(ioe);
        }
    }
    
    void AbrirColores() {
        char letra;
        String Text = "";
        try {
            JFileChooser fc = new JFileChooser(System.getProperty("user.dir"));
            fc.setMultiSelectionEnabled(false);
            fc.setFileFilter(new FiltroColores (true));
            fc.showOpenDialog(this);
            File Abrir = fc.getSelectedFile();//Devuelve el File que vamos a leerName
            fc.setFileSelectionMode(fc.FILES_ONLY);
            if (Abrir != null) {
                nombre2 = fc.getSelectedFile().getName();
            }
            if (Abrir != null) {
                jTextArea3.setText("");
                FileReader Fichero = new FileReader(Abrir);
                BufferedReader leer = new BufferedReader(Fichero);
                while ((Text = leer.readLine()) != null) {
                  jTextArea3.append(Text + "\n"); //append Concatena la linea leida
                }

                direccion_dearchivo2 = Abrir.getAbsolutePath();
                leer.close();

            }

        } catch (IOException ioe) {
            System.out.println(ioe);
        }
    }

    
    
    void AbrirPintar() {
        char letra;
        String Text = "";
        try {
            JFileChooser fcj = new JFileChooser(System.getProperty("user.dir"));
            fcj.setMultiSelectionEnabled(false);
            fcj.setFileFilter(new FiltroPintar (true));
            fcj.showOpenDialog(this);
            File Abrir = fcj.getSelectedFile();//Devuelve el File que vamos a leerName
            fcj.setFileSelectionMode(fcj.FILES_ONLY);
            if (Abrir != null) {
                nombre3 = fcj.getSelectedFile().getName();
            }
            if (Abrir != null) {
                jTextArea1.setText("");
                FileReader Fichero = new FileReader(Abrir);
                BufferedReader leer = new BufferedReader(Fichero);
                while ((Text = leer.readLine()) != null) {
                  jTextArea1.append(Text + "\n"); //append Concatena la linea leida
                }

                direccion_dearchivo3 = Abrir.getAbsolutePath();
                leer.close();

            }

        } catch (IOException ioe) {
            System.out.println(ioe);
        }
    }
    
    
    
    void Guardar(JTextArea Texto) {
        String Total;
        try {
            JFileChooser fc = new JFileChooser(System.getProperty("user.dir"));
            fc.showSaveDialog(this);

            File Guardar = fc.getSelectedFile();
            if (Guardar != null) {
                nombre = fc.getSelectedFile().getName();
                FileWriter Guardax = new FileWriter(Guardar);
                Total = Texto.getText();
                Guardax.write(Total);
                Guardax.close();
            }

        } catch (IOException ioe) {
            System.out.println(ioe);
        }
    }
    
    void Guardarw(JTextArea Texto) {
        if (direccion_dearchivo.equals("")) {
            Guardar(Texto);
        } else {
            int b = JOptionPane.showConfirmDialog(null, "Desea guardar los cambios efectuados en el documento actual");

            if (b == 0) {
                try {

                    FileWriter salida11 = new FileWriter(direccion_dearchivo);
                    salida11.write(Texto.getText());//escribe cada caracter en el archivo adheriendo un parametro para diferenciarlo de los demas
                    salida11.close();

                } catch (IOException ooo) {
                }

            } else {
            }
        }
    }

    
    
    void Guardar(String texto, String path) {
    try{
    File nuevo=new File(path);
   FileWriter Guardax = new FileWriter(nuevo);
                Guardax.write(texto);
                Guardax.close();
    }catch (Exception e){
    
    }
}
    
    
    
    public String GenerarHTMLerroresLexicos(){
    String texto2="";
    texto2+=Inicio;

     int contador=0;
       Iterator<NodoError> d=this.ListaDeErroresLexicos.iterator();
        Compilador.NodoError temporal=null;
        while(d.hasNext()){
        temporal=d.next();
        texto2+="<tr><td>"+contador+"</td> <td><strong>"+temporal.palabra+"</strong></td><td><strong>Elimine Esto</strong></td><td><strong>Error Lexico</strong></td><td>"+temporal.columna+"</td> <td>"+temporal.linea+"</td></tr>"+"\n";
        contador++;
    }
        //texto2+=fin;
    return texto2;
}
  
    
public String GenerarHTMLerroresSintacticos(){
String texto2="";


int contador=0;
Iterator<ErrorSintactico> d=this.ListaDeErroresSintacticos.iterator();
Compilador.ErrorSintactico temporal=null;
while(d.hasNext()){
temporal=d.next();
texto2+="<tr><td>"+contador+"</td> <td><strong>"+temporal.palabra+"</strong></td><td><strong>Cambie esto</strong></td><td><strong>"+temporal.Descripcion+"</strong></td><td>"+temporal.columna+"</td> <td>"+temporal.linea+"</td></tr>"+"\n";
contador++;
}
 texto2+=fin;
return texto2;
}


lexicoLienzos LexicoLienzos=null;
sintacticoLienzos SintacticoLienzos=null;

    public void compilarEscenario(String texto){
    
    
System.out.println("---------------Inicio Analisis LIENZOS---------------");
        try {
             LexicoLienzos=new lexicoLienzos(new BufferedReader( new StringReader(texto)));
                   LexicoLienzos.setListaErrores(ListaDeErroresLexicos);
                   LexicoLienzos.setListaToken(ListaDeToken);
  
            SintacticoLienzos=new sintacticoLienzos(LexicoLienzos); 
            SintacticoLienzos.parse();
           
        } catch (Exception ex) {
            Logger.getLogger(Interfaz.class.getName()).log(Level.SEVERE, null, ex);
        }
System.out.println("----------------Fin Analisis LIENZOS----------------");

}
    
    
    
    lexicoColores LexicoPaint=null;
    sintacticoColores SintacticoPaint=null;

    
    
    public void compilarColores(String texto){
    
    
System.out.println("---------------Inicio Analisis COLORES ---------------");
        try {
             LexicoPaint=new lexicoColores(new BufferedReader( new StringReader(texto)));
                   LexicoPaint.setListaErrores(ListaDeErroresLexicos);
                   LexicoPaint.setListaToken(ListaDeToken);
  
            SintacticoPaint=new sintacticoColores(LexicoPaint); 
            SintacticoPaint.parse();
           
        } catch (Exception ex) {
            Logger.getLogger(Interfaz.class.getName()).log(Level.SEVERE, null, ex);
        }
System.out.println("----------------Fin Analisis COLORES ----------------");

}

        lexicoColorear LexicoColorear=null;
    sintacticoColorear SintacticoColorear=null;

    public void compilarPaint(String texto){
    
    
System.out.println("---------------Inicio Analisis COLOREAR---------------");
        try {
             LexicoColorear=new lexicoColorear(new BufferedReader( new StringReader(texto)));
                   LexicoColorear.setListaErrores(ListaDeErroresLexicos);
                   LexicoColorear.setListaToken(ListaDeToken);
  
            SintacticoColorear=new sintacticoColorear(LexicoColorear); 
            SintacticoColorear.parse();
           
        } catch (Exception ex) {
            Logger.getLogger(Interfaz.class.getName()).log(Level.SEVERE, null, ex);
        }
System.out.println("----------------Fin Analisis COLOREAR----------------");

}
    
    
 static public variables buscarVariable(String nombre){
variables temporal=null;
variables resultado=null;
Iterator<variables> puntero=Interfaz.listaVariables.iterator();

while(puntero.hasNext()){
temporal=puntero.next();
if(temporal.id.equals(nombre)){
resultado=temporal;
}
System.out.println(temporal.id+"  "+temporal.valor);
}
return resultado;
}
  
 

    
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        AbrirLienzos();
}//GEN-LAST:event_jButton9ActionPerformed

private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
direccion_dearchivo=direccion_dearchivo1;
nombre=nombre1;
    Guardarw(jTextArea4);
}//GEN-LAST:event_jButton10ActionPerformed

private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
            jTextArea4.setText("");
            direccion_dearchivo = "";
            direccion_dearchivo1="";
nombre1="";

}//GEN-LAST:event_jButton11ActionPerformed

private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
direccion_dearchivo=direccion_dearchivo1;
nombre=nombre1;
    if(jTextArea4.getText().equals("")){
     JOptionPane.showMessageDialog(null, "Abra un archivo o edite las instrucciones antes de compilar");
     }
    if(direccion_dearchivo.equals("") && !jTextArea4.getText().equals("")){
    compilarEscenario(jTextArea4.getText());
    }
    if(!direccion_dearchivo.equals("") && !jTextArea4.getText().equals("")){
    this.Guardarw(jTextArea4);
    compilarEscenario(jTextArea4.getText());
    
}   
       

}//GEN-LAST:event_jButton12ActionPerformed

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
direccion_dearchivo=direccion_dearchivo2;
nombre=nombre2;
    Guardarw(jTextArea3);
}//GEN-LAST:event_jButton4ActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    AbrirColores();
}//GEN-LAST:event_jButton3ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
            jTextArea3.setText("");
            direccion_dearchivo = "";
            direccion_dearchivo2="";
nombre2="";
}//GEN-LAST:event_jButton2ActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
direccion_dearchivo=direccion_dearchivo2;
nombre=nombre2;    
if(jTextArea3.getText().equals("")){
     JOptionPane.showMessageDialog(null, "Abra un archivo o edite las instrucciones antes de compilar");
     }
    if(direccion_dearchivo.equals("") && !jTextArea3.getText().equals("")){
    compilarColores(jTextArea3.getText());
    }
    if(!direccion_dearchivo.equals("") && !jTextArea3.getText().equals("")){
    this.Guardarw(jTextArea3);
    compilarColores(jTextArea3.getText());
    
    }   
}//GEN-LAST:event_jButton1ActionPerformed

private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed
                    AbrirPintar();
}//GEN-LAST:event_jButton13ActionPerformed

private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
direccion_dearchivo=direccion_dearchivo3;
nombre=nombre3;
    Guardarw(jTextArea1);
}//GEN-LAST:event_jButton14ActionPerformed

private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton15ActionPerformed
            jTextArea1.setText("");
            direccion_dearchivo = "";
            direccion_dearchivo3="";
nombre3="";
}//GEN-LAST:event_jButton15ActionPerformed

private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton16ActionPerformed
direccion_dearchivo=direccion_dearchivo3;
nombre=nombre3;
    
    if(jTextArea1.getText().equals("")){
     JOptionPane.showMessageDialog(null, "Abra un archivo o edite las instrucciones antes de compilar");
     }
    if(direccion_dearchivo.equals("") && !jTextArea1.getText().equals("")){
    compilarPaint(jTextArea1.getText());
    }
    if(!direccion_dearchivo.equals("") && !jTextArea1.getText().equals("")){
    this.Guardarw(jTextArea1);
    compilarPaint(jTextArea1.getText());
    
    }
}//GEN-LAST:event_jButton16ActionPerformed

private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem9ActionPerformed

    String html="";
    
   html=this.GenerarHTMLerroresLexicos();
   html+=this.GenerarHTMLerroresSintacticos();
    html+=this.fin;
    
    this.Guardar(html, "MostrarErrores.html");

      Runtime ejecutor = Runtime.getRuntime();
        try {
            File dd = new File("MostrarErrores.html");
            Desktop d = Desktop.getDesktop();
            d.open(dd);
        } catch (IOException ex) {
            System.out.println("el maldito error");
        }
        
       
}//GEN-LAST:event_jMenuItem9ActionPerformed

private void jMenu2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu2ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jMenu2ActionPerformed

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
this.limpiar();
}//GEN-LAST:event_jButton5ActionPerformed

private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed

}//GEN-LAST:event_jMenuItem5ActionPerformed

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed

    escogerLienzos lien = new escogerLienzos();
    lien.setVisible(true);
    
     
}//GEN-LAST:event_jMenuItem1ActionPerformed

private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu1ActionPerformed
       

        if (direccion_dearchivo.equals("") && jTextArea1.getText().equals("") && jTextArea3.getText().equals("")&& jTextArea4.getText().equals("")) {
            System.exit(0);
        }

        if (direccion_dearchivo.equals("")) {

            int b = JOptionPane.showConfirmDialog(null, "Desea guardar los cambios efectuados en el documento actual");

            if (b == 1) {
                System.exit(0);
            }
            if (b == 0) {
                Guardar(jTextArea1);
                Guardar(jTextArea3);
                Guardar(jTextArea4);
                System.exit(0);
            }

        } else {
            if (!jTextArea1.getText().equals("") && !jTextArea3.getText().equals("") && !jTextArea4.getText().equals("")) {

                int b = JOptionPane.showConfirmDialog(null, "Desea guardar los cambios efectuados en el documento actual");

                if (b == 1) {

                    System.exit(0);
                }
                if (b == 0) {
                    try {


                        FileWriter salida8 = new FileWriter(direccion_dearchivo);


                        salida8.write(jTextArea1.getText());//escribe cada caracter en el archivo adheriendo un parametro para diferenciarlo de los demas
                        salida8.write(jTextArea3.getText());//escribe cada caracter en el archivo adheriendo un parametro para diferenciarlo de los demas
                        salida8.write(jTextArea4.getText());//escribe cada caracter en el archivo adheriendo un parametro para diferenciarlo de los demas

                        salida8.close();


                        System.exit(0);
                    } catch (IOException ooo) {
                        System.out.println("entro al catch");
                    }
                } else {
                    int ebert = JOptionPane.showConfirmDialog(null, "seguro que desea salir");

                    if (ebert == 1 || ebert == 2) {
                    } else {

                        System.exit(0);
                    }

                }
            }
        }

    

}//GEN-LAST:event_jMenu1ActionPerformed

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
            Acercade ac = new Acercade();
            ac.setVisible(true);
}//GEN-LAST:event_jMenuItem2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Interfaz.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Interfaz.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Interfaz.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Interfaz.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Interfaz().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton15;
    private javax.swing.JButton jButton16;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JTabbedPane jTabbedPane2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea3;
    private javax.swing.JTextArea jTextArea4;
    // End of variables declaration//GEN-END:variables
}
